﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MSBDATAModel;

public partial class Admin_CapNhatBieuPhiMoi : System.Web.UI.Page
{
    MSBDATAEntities entities = new MSBDATAEntities();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            Calendar1.SelectedDate = DateTime.Now;
            int kyHanMoiNhat = entities.KY_HAN.ToList().Count - 1;

            KY_HAN k = entities.KY_HAN.ToList()[kyHanMoiNhat];
            TextBox1.Text = k.LSKH1Thang.ToString();
            TextBox2.Text = k.LSKH2Thang.ToString();
            TextBox3.Text = k.LSKH3Thang.ToString();
            TextBox4.Text = k.LSKH4Thang.ToString();
            TextBox5.Text = k.LSKH5Thang.ToString();
            TextBox6.Text = k.LSKH6Thang.ToString();
            TextBox7.Text = k.LSKH7Thang.ToString();
            TextBox8.Text = k.LSKH8Thang.ToString();
            TextBox9.Text = k.LSKH9Thang.ToString();
            TextBox10.Text = k.LSKH10Thang.ToString();
            TextBox11.Text = k.LSKH11Thang.ToString();
            TextBox12.Text = k.LSKH12Thang.ToString();
            TextBox13.Text = k.LSKhongKH.ToString();
            Calendar1.SelectedDate = k.NgayApDung??DateTime.Now;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            KY_HAN k = KY_HAN.CreateKY_HAN(0);
            k.NgayApDung = Calendar1.SelectedDate;
            k.LSKH1Thang = float.Parse(TextBox1.Text);
            k.LSKH2Thang = float.Parse(TextBox2.Text);
            k.LSKH3Thang = float.Parse(TextBox3.Text);
            k.LSKH4Thang = float.Parse(TextBox4.Text);
            k.LSKH5Thang = float.Parse(TextBox5.Text);
            k.LSKH6Thang = float.Parse(TextBox6.Text);
            k.LSKH7Thang = float.Parse(TextBox7.Text);
            k.LSKH8Thang = float.Parse(TextBox8.Text);
            k.LSKH9Thang = float.Parse(TextBox9.Text);
            k.LSKH10Thang = float.Parse(TextBox10.Text);
            k.LSKH11Thang = float.Parse(TextBox11.Text);
            k.LSKH12Thang = float.Parse(TextBox12.Text);
            k.LSKhongKH = float.Parse(TextBox13.Text);

            entities.AddToKY_HAN(k);
            entities.SaveChanges();
            this.LabelStatus.Text = "Cập nhật thành công";
        }catch(Exception )
        {
            this.LabelStatus.Text = "Cập nhật thất bại, vui lòng kiểm tra lại dữ liệu nhập";
        }
    }
}